// 存储默认状态
chrome.runtime.onInstalled.addListener(() => {
  chrome.storage.local.set({ enabled: true });
  updateIcon(true);
});

// 点击图标切换状态
chrome.action.onClicked.addListener(() => {
  chrome.storage.local.get(['enabled'], (result) => {
    const newState = !result.enabled;
    chrome.storage.local.set({ enabled: newState });
    updateIcon(newState);
  });
});

// 更新图标状态
function updateIcon(enabled) {
  const title = enabled ? '百度网盘自动播放(已启用)' : '百度网盘自动播放(已禁用)';
  chrome.action.setTitle({ title });
  chrome.action.setIcon({
    path: {
      48: enabled ? 'icons/icon48.png' : 'icons/icon48_disabled.png'
    }
  });
}

// 监听来自content script的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.type === 'getStatus') {
        chrome.storage.local.get(['enabled'], (result) => {
            sendResponse({ enabled: result.enabled });
        });
        return true;
    }
}); 